﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using DCT.Huiteng.Utility.Config;
using System.Text;
using DCT.Huiteng.Utility;
using DCT.Huiteng.AdminSystem.Web.Codes;

namespace DCT.Huiteng.AdminSystem.Web
{
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        private static string cacheMenuHTML = "";
        protected string GenerateMenuHTML()
        {
            if (string.IsNullOrEmpty(cacheMenuHTML))
            {
                StringBuilder sb = new StringBuilder();

                //{0}名称 {1}子菜单html
                string divBannerFormat = "<div title=\"{0}\" style=\"padding: 10px; text-align: center\">{1}</div>";
                //{0}名称 {1}url
                string divSubFormat = "<p><a class=\"targetframe\" href=\"{1}\">{0}</a></p>";
                //配置内容                
                var cp = GeneralToolCode.LoadConfig("menu");
                
                //循环主菜单
                foreach (var banner in cp.GetListKV("banner"))
                {
                    var bannerkv = CollectionUtility.Convert(banner);
                    string id = bannerkv["id"];
                    string name = bannerkv["name"];

                    //循环子菜单
                    StringBuilder subBannerHtml = new StringBuilder();
                    string subbannerkey = "banner_" + id;
                    foreach (var subbanner in cp.GetListKV(subbannerkey))
                    {
                        var subBannerKV = CollectionUtility.Convert(subbanner);
                        subBannerHtml.AppendFormat(divSubFormat
                            , System.Web.HttpUtility.HtmlEncode(subBannerKV["name"])
                            , this.ResolveUrl(subBannerKV["url"]));
                    }

                    sb.AppendFormat(divBannerFormat, name, subBannerHtml.ToString());
                }
                cacheMenuHTML = sb.ToString();
            }
            return cacheMenuHTML;
        }
    }
}